"IF" Statement that detects decimal input
I need to alert when a decimal is entered in the %Increase: $User = Read-Host "Enter an alias" $Increase = Read-Host "Enter % Increase" $DecException = $Increase $colitems = Get-Mailbox -identity $User | Select-object IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota FOREACH ($ColItem in $Colitems) { $Warning = ([string]$ColItem.IssueWarningQuota).split("K")[0] $ProhibitSend = ([string]$ColItem.ProhibitSendQuota).split("K")[0] $ProhibitSendReceive = ([string]$ColItem.ProhibitSendReceiveQuota).split("K")[0] } #Write-Host "Prohibit Send: $ProhibitSend" #Write-Host "Prohibit Receive: $ProhibitReceive" #Write-Host "Issue Warning: $Warning"
August 28th, 2012 1:54pm

On Tue, 28 Aug 2012 17:54:36 +0000, RJB90 wrote: > > >I need to alert when a decimal is entered in the %Increase: > >$User = Read-Host "Enter an alias" $Increase = Read-Host "Enter % Increase" $DecException = $Increase $colitems = Get-Mailbox -identity $User | Select-object IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota > >FOREACH ($ColItem in $Colitems) { $Warning = ([string]$ColItem.IssueWarningQuota).split("K")[0] $ProhibitSend = ([string]$ColItem.ProhibitSendQuota).split("K")[0] $ProhibitSendReceive = ([string]$ColItem.ProhibitSendReceiveQuota).split("K")[0] } #Write-Host "Prohibit Send: $ProhibitSend" #Write-Host "Prohibit Receive: $ProhibitReceive" #Write-Host "Issue Warning: $Warning" How about: $p = $increase.split(".") if ($p.length -gt 1) { "decimal present in data" } I gotta say I've never seen the quotas dealt with in the way you're doing it. How about this instead? $increase = read-host "Enter % Increase" while (($increase.split(".")).length -gt 1) { "Value cannot cantain a decimal point!" $increase = read-host "Enter % Increase" } $grow = 1.0 + ($increase/100) $m = get-mailbox -identity $user -resultsize 1 $setmbx = $false if ($m.issuewarningquota.isunlimited -eq $false) { $m.issuewarningquota = $m.issuewarningquota.value.tokb() * $grow $setmbx = $true } if ($m.prohibitsendquota.isunlimited -eq $false) { $m.prohibitsendquota = $m.prohibitsendquota.value.tokb() * $grow $setmbx = $true } if ($m.prohibitsendreceivequota.isunlimited -eq $false) { $m.prohibitsendreceivequota = $m.prohibitsendreceivequota.value.tokb() * $grow $setmbx = $true } if ($setmbx) { $m | set-mailbox } --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
August 28th, 2012 8:54pm

Can you help me with this: DO {[int]$Increase = Read-Host "Enter % Increase"; $p = $increase.split(".")} UNTIL ($p.length -gt 1) This is the logic that i am trying to work with, I am not understanding what you posted. I need to detect when a user puts a decimal and kick back to say only whole numbers are permitted. When i am running my script i am having a "system.double" issue. I am assuming that i am comparing a number with a string. Error: Method invocation failed because [System.Double] doesn't contain a method named 'split'. At line:1 char:19 + $b = [int]$a.split <<<< (".") + CategoryInfo : InvalidOperation: (split:String) [], RuntimeExce ption + FullyQualifiedErrorId : MethodNotFound
August 29th, 2012 3:46pm

I would assume the same. I passed it by some colleagues and they recommended that if a decimal was inputted it generates an "Error" message. More of a sanity checker. Thanks for your help.
Free Windows Admin Tool Kit Click here and download it now
August 29th, 2012 6:22pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics